import java.util.*;
import java.io.*;
/**
 *
 * @author jessica
 */
public class SorryMain
{
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args)
    {
        //Variable Declaration
        Board board;
        boolean badChoice = false;
        int player;
        int selection = -1;
        int gameSelection;
        Scanner input = new Scanner(System.in);
        String rawSelection;

        //Repeat the main logic until the user wishes to quit
        while (selection != 4)
        {
            //Print main menu and get selection
            System.out.println("Welcome to the game of Sorry!");
            System.out.println("\nMAIN MENU");
            System.out.println("1 - New Game");
            System.out.println("2 - Load Game");
            System.out.println("3 - View Stats");
            System.out.println("4 - Exit");
            System.out.print("What would you like to do? Enter a choice from 1 to 4: ");
            rawSelection = input.next();
            System.out.println("\n");

            //Error trapping to make sure the user entered a number between 1 and 4
            badChoice = false;
            do
            {
                if (rawSelection.length() == 1 && Character.isDigit(rawSelection.charAt(0)))
                {
                    selection = Integer.parseInt(rawSelection);
                    if (selection > 4)
                    {
                        badChoice = true;
                    }
                    else
                    {
                        badChoice = false;
                    }
                }

                else
                {
                    badChoice = true;
                }

                if (badChoice)
                {
                    System.out.println("Choice must be between 1 and 4, inclusive");
                    System.out.print("Enter a choice from 1 to 4: ");
                    rawSelection = input.next();
                    System.out.println("\n");
                }
            }
            while (badChoice);

            //Load game
            if (selection == 2)
            {
                System.out.println("Load Game not developed yet");
            }

            //View stats
            else if (selection == 3)
            {
                System.out.println("View Stats not developed yet");
            }

            else if (selection == 4)
            {
                System.out.println("Good bye!");
            }

            //Player takes turn
            else
            {
                gameSelection = 1;
                player = 0;

                while (gameSelection == 1)
                {
                    System.out.println("GAME MENU");
                    System.out.println("1 - Select Move");
                    System.out.println("2 - Save and Quit");
                    System.out.println("3 - Quit without Saving");
                    rawSelection = input.next();
                    badChoice = false;

                    do
                    {
                        if (rawSelection.length() == 1 && Character.isDigit(rawSelection.charAt(0)))
                        {
                            gameSelection = Integer.parseInt(rawSelection);
                            if (gameSelection > 4)
                            {
                                badChoice = true;
                            }
                            else
                            {
                                badChoice = false;
                            }
                        }

                        else
                        {
                            badChoice = true;
                        }

                        if (badChoice)
                        {
                            System.out.println("Choice must be 1 or 2");
                            System.out.print("Make a selection: ");
                            rawSelection = input.next();
                            System.out.println("\n");
                        }
                    }
                    while (badChoice);

                    if (gameSelection == 1)
                        takeTurn(player);

                    player = (player + 1) % 4;
                }
            }
        }
    }

    private static void takeTurn(int player)
    {
        System.out.println("takeTurn not developed yet");
    }

}
